# -*- coding: utf-8 -*-
import json
import codecs
import sys
reload(sys)   
sys.setdefaultencoding('utf8') 
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html


class GuahaowangPipeline(object):
	def __init__(self):
		self.file = codecs.open("E:\jiaocheng\F\Project\\guahaowang\data\\hospital_list.json",'wb',encoding = 'utf-8')


	def process_item(self, item, spider):
		#print item
		#医院名称
		hospital = item['hospital']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#医院等级
		grade = item['grade']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#医院地址
		address = item['address']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#医院电话
		tel_num = item['tel_num']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#官方网站
		website = item['website']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#简介
		about = item['about']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#预约量
		yu_yue_liang = item['yu_yue_liang']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#导医服务
		dao_yi_fu_wu = item['dao_yi_fu_wu']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#患者评价
		huan_zhe_ping_jia = item['huan_zhe_ping_jia']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		#候诊时间
		hou_zhen_shi_jian = item['hou_zhen_shi_jian']#[0].replace('\n','').replace('\t','').replace('\r','').replace(' ','')

		dic = {
				#医院名称
				"hospital" : hospital,

				#医院等级
				"grade" : grade,

				#医院地址
				"address" : address,

				#医院电话
				"tel_num" : tel_num,

				#官方网站
				"website" : website,

				#简介
				"about" : about,

				#预约量
				"yu_yue_liang" : yu_yue_liang,

				#导医服务
				"dao_yi_fu_wu" : dao_yi_fu_wu,

				#患者评价
				"huan_zhe_ping_jia" : huan_zhe_ping_jia,

				#候诊时间
				"hou_zhen_shi_jian" : hou_zhen_shi_jian,
				
				}


		dicts = json.dumps(dict(item),ensure_ascii=False)
		line = dicts + '\n'
		print "load.....save....."
		self.file.write(line)


		return item

	def close_spider(self,spider):
		self.file.close()

"""	
	#医院名称
	hospital

	#医院等级
	grade

	#医院地址
	address

	#医院电话
	tel_num

	#官方网站
	website

	#简介
	about

	#预约量
	yu_yue_liang

	#导医服务
	dao_yi_fu_wu

	#患者评价
	huan_zhe_ping_jia

	#候诊时间
	hou_zhen_shi_jian

"""